//
//  YBVCTool.m
//  XHGY_Agent
//
//  Created by 尚往文化 on 17/6/8.
//  Copyright © 2017年 YBing. All rights reserved.
//

#import "YBVCTool.h"

@implementation YBVCTool

+ (UIViewController *)getVCForView:(UIView *)view
{
    for (UIView *next = [view superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}

+ (UIViewController *)getCurrentVC
{
    UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
    UIViewController *rootVC = window.rootViewController;
    if ([rootVC isKindOfClass:NSClassFromString(@"YBMainController")]) {
        UINavigationController *nav = [rootVC valueForKey:@"nav"];
        return nav.topViewController;
    } else if ([rootVC isKindOfClass:[UINavigationController class]]) {
        return ((UINavigationController *)rootVC).topViewController;
    } else {
        return rootVC;
    }
}


@end
